home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12523 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: RAND_MAX
  5. Date: 1 Apr 1996 14:41:58 GMT
  6. Organization: University of Guelph
  7. Message-ID: <4jopvm$9sm@ccshst05.cs.uoguelph.ca>
  8. References: <4jnr55$e6l@skivs.ski.org>
  9. NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Gemini Thunder (gt@ns.oon.or.jp) wrote:
  13. : K&R2 says:
  14. :   "rand returns a a pseudo-random integer in the range 0 to RAND_MAX,
  15. : which is at least 32767"
  16.  
  17. : It looks like RAND_MAX is not required to be the same as any other
  18. : limit (such as MAX_INT, etc.), that is fine, but why?  
  19. : Wouldn't it be easier if RAND_MAX == MAX_INT or some other value?  
  20.  
  21. : The reason I say this is how can you be sure your array will hold a
  22. : RAND_MAX sized integer, without some checking before hand, if RAND_MAX
  23. : is out there doing its own thing?
  24.  
  25.   I wrote and debugged a program on my PC using TurboC with its 16 bit 
  26. integers and then moved it to an SGI with 32 bit integers, assuming that 
  27. RAND_MAX would be much larger.  I was suprised to find that in fact it 
  28. was the same on the two systems, and I had to rewrite some code to get 
  29. random numbers of 31 bits.  
  30.   Since rand() returns an integer you can be sure that if your array is 
  31. of type integer it will hold the value returned by rand().  Was that the 
  32. question? 
  33. Toby Hay    thay@uoguelph.ca
  34.